import {
  Body,
  Controller,
  Get,
  Post,
  Request,
  UseGuards,
} from '@nestjs/common';
import { UsersService } from './users.service';
import { paginationInterfacesImpl } from '../utils/pagination';
import { AuthGuard } from '@nestjs/passport';

@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get('getAll')
  getHello(@Body() data): Promise<paginationInterfacesImpl> {
    console.log('dat', data);
    return this.usersService.findAll(data);
  }

  // 更新用户信息
  @Post('update')
  @UseGuards(AuthGuard('jwt'))
  updateUser(@Body() bodyData: any, @Request() req) {
    const id = req.user.id;
    return this.usersService.updateUser({ id, ...bodyData });
  }

  // 获取用户信息
  @Post('info')
  @UseGuards(AuthGuard('jwt'))
  getUserInfo(@Body() bodyData: any, @Request() req) {
    const user_id = req.user.id;
    return this.usersService.getUserInfo(user_id);
  }
}
